package com.msmall.community.diary.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.msmall.base.model.BaseObject;
import com.msmall.base.util.Constants;
import com.msmall.base.util.StringUtil;
import com.msmall.community.diary.util.DiaryUtil;

/**
 * 相册
 */
@Entity
@Table(name="base_diary")
public class Diary extends BaseObject{

	private static final long serialVersionUID = -5483140057492793248L;

	@Id
	@Column(name="diary_id")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Long diaryid;
	
	@Column(name="user_id")
	private Long userid;
	
	/**
	 * 标题
	 */
	@Column(name="title", length=45)
	private String title;
	
	/**
	 * 内容的摘要
	 */
	@Column(name="content_abstract", length=300)
	private String contentAbstract;
	
	/**
	 * 查看次数
	 */
	@Column(name="click_amount")
	private Integer clickAmount;
	
	/**
	 * 评论次数
	 */
	@Column(name="reply_amount")
	private Integer replyAmount;
	
	/**
	 * 赞次数
	 */
	@Column(name="top_amount")
	private Integer topAmount;
	
	@Column(name="file_path", length=50)
	private String filePath; // 文件路径

	@Column(name="file_name", length=50)
	private String fileName; //文件名称
	
	@Column(name="file_ext", length=6)
	private String fileExt; // 文件扩展名
	
	/**
	 * ConstantDB.REPLY是否允许评论
	 */
	@Column(name="reply", length=1)
	private Short reply;
	
	/**
	 * 删除标记
	 */
	@Column(name="enabled", length=1)
	private Short enabled;
	
	@Column(name="create_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date createTime;
	
	/**
	 * 上次修改相片的日期
	 */
	@Column(name="last_modify_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastModifyTime;
	
	@Transient
	private String content;
	
	
	public String getContentAbstract100(){
		return StringUtil.getChineseSubString(contentAbstract, 100, ""); 
	}
	
	public String getHtmlPath(){
		return Constants.FILE_SEP + getAbsolutePath(Constants.USER_AGENT_TYPE_HTML);
	}
	private String getAbsolutePath(String uat){
		String path = DiaryUtil.getPrefixPath(uat) + filePath + fileName + fileExt;
		return path;
	}
	public Long getDiaryid() {
		return diaryid;
	}

	public void setDiaryid(Long diaryid) {
		this.diaryid = diaryid;
	}

	public Long getUserid() {
		return userid;
	}

	public void setUserid(Long userid) {
		this.userid = userid;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContentAbstract() {
		return contentAbstract;
	}

	public void setContentAbstract(String contentAbstract) {
		this.contentAbstract = contentAbstract;
	}

	public Integer getClickAmount() {
		return clickAmount;
	}

	public void setClickAmount(Integer clickAmount) {
		this.clickAmount = clickAmount;
	}

	public Integer getReplyAmount() {
		return replyAmount;
	}

	public void setReplyAmount(Integer replyAmount) {
		this.replyAmount = replyAmount;
	}

	public Integer getTopAmount() {
		return topAmount;
	}

	public void setTopAmount(Integer topAmount) {
		this.topAmount = topAmount;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getFileExt() {
		return fileExt;
	}

	public void setFileExt(String fileExt) {
		this.fileExt = fileExt;
	}

	public Short getReply() {
		return reply;
	}

	public void setReply(Short reply) {
		this.reply = reply;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getLastModifyTime() {
		return lastModifyTime;
	}

	public void setLastModifyTime(Date lastModifyTime) {
		this.lastModifyTime = lastModifyTime;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Short getEnabled() {
		return enabled;
	}

	public void setEnabled(Short enabled) {
		this.enabled = enabled;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean equals(Object o) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return 0;
	}

}
